package weaver.interfaces.htsc.hrm;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.doc.detail.util.DocDownloadCheckUtil;

import sun.misc.BASE64Decoder;
import weaver.conn.RecordSet;
import weaver.docs.docs.ImageFileIdUpdate;
import weaver.general.*;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.*;

public class OrganizationSyn {

    /***
     *  部门同步（不同步部门负责人等）
     * @param url
     * @return
     */
    public Map<String,String> doDeptSyn(String url,Map<String,String> headMap)
    {
        BaseBean bb = new BaseBean();
        PropBean pb = new PropBean();
        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        String HT0001 = pb.getPropName("HT0001");
        bb.writeLog("doDeptSynALL");

        int allcount = 0;

        int updatesuccesscount = 0;
        int updateerrorcount = 0;
        int insertsuccesscount = 0;
        int inserterrorcount = 0;
        int exceptioncount = 0;

        int updatedefinesuccesscount = 0;
        int updatedefineerrorcount = 0;
        int insertdefinesuccesscount = 0;
        int insertdefineerrorcount = 0;

        RecordSet rs = new RecordSet();

        //默认所有部门挂在华泰集团这个分部下
        String subcompanyid1 = OrganizationSynUtil.getSubcomIdByCode(HT0001);
        Map<String,String> map = new HashMap<String,String>();
        try{
            String response = OrganizationSynUtil.sendPost(url,"",headMap);
            JSONArray deptArray = JSONArray.parseArray(response);
            allcount = deptArray.size();
            for(int i=0;i<deptArray.size();i++)
            {
                JSONObject deptJson = deptArray.getJSONObject(i);
                String deptCode = Util.null2String(deptJson.getString("deptCode"));//部门编码
                String deptName = Util.null2String(deptJson.getString("deptName"));//部门名称
                String deptCodePath = Util.null2String(deptJson.getString("deptCodePath"));//部门编码
                String deptNamePath = Util.null2String(deptJson.getString("deptNamePath"));//部门名称路径
                String parentDeptCode = Util.null2String(deptJson.getString("parentDeptCode"));//上级部门编码
                String deptCity = Util.null2String(deptJson.getString("deptCity"),"null");//部门所在城市

                String deptTypeName = Util.null2String(deptJson.getString("deptTypeName"));//部门类型1名称
                String deptTypeCode = Util.null2String(deptJson.getString("deptTypeCode"));//部门类型1编码
                String deptType2Name = Util.null2String(deptJson.getString("deptType2Name"));//部门类型2名称
                String deptType2Code = Util.null2String(deptJson.getString("deptType2Code"));//部门类型2编码
                String deptDepth = Util.null2String(deptJson.getString("deptDepth"));//部门树所在深度
                String deptSortNum = Util.null2String(deptJson.getString("deptSortNum"));//部门排序编码
                String deptState = Util.null2String(deptJson.getString("deptState"));//部门状态

                String isActive = Util.null2String(deptJson.getString("isActive")); //
                if(!"ACTIVE".equals(isActive)){
                    deptState = "1";
                }
                String isLeafDept = "0";//是否没有子部门
                if(deptJson.getBoolean("isLeafDept"))
                {
                    isLeafDept = "1";
                }

                String deptScaleLevelCode = Util.null2String(deptJson.getString("deptScaleLevelCode"));//部门规模代码
                String deptScaleLevelName = Util.null2String(deptJson.getString("deptScaleLevelName"));//部门规模名称
                String departmentType = Util.null2String(deptJson.getString("departmentType"));//自定义部门类型
                departmentType = OrganizationSynUtil.getDepartmentType(departmentType);
                //String docNumAbbreviation = Util.null2String(deptJson.getString("docNumAbbreviation"));//部门简称
                //String docNumber = Util.null2String(deptJson.getString("docNumber"));//部门简称
                String cmpAbbre = Util.null2String(deptJson.getString("cmpAbbre"));//分公司简称

                //查询上级部门对应的ID
                String supDepid = null;
                if(!"".equals(parentDeptCode))
                {
                    supDepid = OrganizationSynUtil.getDeptIdByCode(parentDeptCode) +"";
                }
                if("".equals(supDepid) || supDepid==null){
                    supDepid="0";
                }
                try{
                    String deptId = OrganizationSynUtil.getDeptIdByCode(deptCode);
                    if(!"".equals(deptId)){ //更新部门数据
                        String deptUpdateSql =  " update hrmdepartment set departmentmark='"+deptName+"',departmentname='"+deptName+"',canceled='"+deptState+"'," +
                                " subcompanyid1='"+subcompanyid1+"',showorder='"+deptSortNum+"', supdepid='"+supDepid+"'  where departmentcode='"+deptCode+"' ";
                        boolean flag = rs.executeUpdate(deptUpdateSql);
                        if(flag)
                        {
                            updatesuccesscount++;
                        }else{
                            updateerrorcount++;
                        }
                    }else{ //插入部门数据

                        String deptNum = Util.null2String(deptJson.getString("deptNum"));
                        int intdeptNum = 0;
                        try{
                            if(!"".equals(deptNum)){
                                intdeptNum = Util.getIntValue(deptNum);
                            }else{
                                intdeptNum = -1;
                            }
                        }catch (Exception e){
                            bb.writeLog("OrganizationSyn-e:"+e);
                            intdeptNum = -2;
                        }
                        bb.writeLog(deptCode+":"+deptName+":"+"insert"+":"+isActive+":"+deptState+"deptNum:"+deptNum);
                        if(intdeptNum >0)
                        {
                            String deptInsertSql = " insert into hrmdepartment(id,departmentmark,departmentname,departmentcode," +
                                    " canceled,subcompanyid1,supdepid,showorder) values(?,?,?,?,?,?,?,?) ";
                            boolean flag =  rs.executeUpdate(deptInsertSql,new Object[]{intdeptNum+"",deptName,deptName,deptCode,deptState,subcompanyid1,supDepid,deptSortNum});
                            if(flag)
                            {
                                insertsuccesscount++;
                            }else{
                                inserterrorcount++;
                            }
                        }

                        //插入新部门后取部门id
                        deptId = OrganizationSynUtil.getDeptIdByCode(deptCode);
                    }

                    JSONArray departmentAreaManagers = deptJson.getJSONArray("departmentAreaManagers");//投行区域负责人
                    String txqyfzr = OrganizationSynUtil.getUserIdsByCodesObj(departmentAreaManagers); //主账号 多人
                    String parentSaleCode = Util.null2String(deptJson.getString("parentSaleCode"));
                    //更新部门自定义字段信息
                    String deptDefinedId = OrganizationSynUtil.getDeptDefineidByDeptid(deptId);
                    bb.writeLog("deptDefinedId:"+deptDefinedId+"--deptName:"+deptName+"--deptCode:"+deptCode+"--parentSaleCode:"+parentSaleCode);
                    //更新部门自定义字段信息
                    if(!"".equals(deptDefinedId))
                    {
                        String deptUpdateSql2 = " update hrmdepartmentdefined set deptCodePath='"+deptCodePath+"',deptNamePath='"+deptNamePath+"',deptCity='"+deptCity+"',deptTypeName='"+deptTypeName+"',deptTypeCode='"+deptTypeCode+"',deptType2Name='"+deptType2Name+"',deptType2Code='"+deptType2Code+"'," +
                                " deptDepth='"+deptDepth+"',isLeafDept='"+isLeafDept+"',deptScaleLevelCode='"+deptScaleLevelCode+"',deptScaleLevelName='"+deptScaleLevelName+"',departmentType='"+departmentType+"',cmpAbbre='"+cmpAbbre+"',txqyfzr='"+txqyfzr+"',parentSaleCode='"+parentSaleCode+"' where id='"+deptDefinedId+"' ";
                        bb.writeLog(deptUpdateSql2);
                        boolean flag = rs.executeUpdate(deptUpdateSql2);
                        if(flag)
                        {
                            insertdefinesuccesscount++;
                        }else{
                            insertdefineerrorcount++;
                        }
                    }else{
                        String deptInsertSql2 = " insert into hrmdepartmentdefined(deptid,deptCodePath,deptNamePath,deptCity," +
                                " deptTypeName,deptTypeCode,deptType2Name,deptType2Code,deptDepth,isLeafDept," +
                                " deptScaleLevelCode,deptScaleLevelName,departmentType,cmpAbbre,txqyfzr,parentSaleCode) " +
                                " values("+deptId+",'"+deptCodePath+"','"+deptNamePath+"','"+deptCity+"','"+ deptTypeName+"','"+deptTypeCode+"','"+deptType2Name+"','"+deptType2Code+"','"+deptDepth+"','"+isLeafDept+"','"+deptScaleLevelCode+"','"+deptScaleLevelName+"','"+departmentType+"','"+cmpAbbre+"','"+txqyfzr+"','"+parentSaleCode+"')";

                        boolean flag =  rs.execute(deptInsertSql2);
                        if(flag)
                        {
                            updatedefinesuccesscount++;
                        }else{
                            updatedefineerrorcount++;
                        }
                    }

//                    String deptabbrdefid = "" ;
//                    String sql = " select id from workflow_deptabbrdef where departmentid="+deptId;
//                    rs.execute(sql);
//                    if(rs.next()){
//                        deptabbrdefid = Util.null2String(rs.getString("id"));
//                    }
//                    if(!"".equals(deptabbrdefid)){
//                        sql = " update workflow_deptabbrdef set abbr='"+ docNumAbbreviation+"' where id="+deptabbrdefid ;
//                        rs.execute(sql);
//                    }else{
//                        sql = " insert into workflow_deptabbrdef(departmentid,abbr) values("+deptId+",'"+docNumAbbreviation+"') " ;
//                        rs.execute(sql);
//                    }
                }catch (Exception e){
                    e.printStackTrace();
                    bb.writeLog("OrganizationSyn-e:"+e);
                    exceptioncount++;
                    bb.writeLog("部门编号为"+deptCode+"的数据同步失败，data:"+deptJson.toJSONString());
                }
            }
        }catch (Exception e){
            bb.writeLog("OrganizationSyn-e:"+e);
        }

        map.put("updatesuccesscount",updatesuccesscount+"");
        map.put("updateerrorcount",updateerrorcount+"");
        map.put("insertsuccesscount",insertsuccesscount+"");
        map.put("inserterrorcount",inserterrorcount+"");
        map.put("updatedefinesuccesscount",updatedefinesuccesscount+"");
        map.put("updatedefineerrorcount",updatedefineerrorcount+"");
        map.put("insertdefinesuccesscount",insertdefinesuccesscount+"");
        map.put("insertdefineerrorcount",insertdefineerrorcount+"");
        map.put("exceptioncount",exceptioncount+"");
        map.put("allcount",allcount+"");
        return map;
    }



    /***
     *  部门同步（不同步部门负责人等）
     * @param url
     * @return
     */
    public Map<String,String> doDeptAbSyn(String url,Map<String,String> headMap)
    {



        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        BaseBean bb = new BaseBean();
        PropBean pb = new PropBean();
        RecordSet rs = new RecordSet();
        String HT0001 = pb.getPropName("HT0001");
        bb.writeLog("doDeptAbSyn");

        int allcount = 0;

        int updatesuccesscount = 0;
        int updateerrorcount = 0;
        int insertsuccesscount = 0;
        int inserterrorcount = 0;
        int exceptioncount = 0;

        int updatedefinesuccesscount = 0;
        int updatedefineerrorcount = 0;
        int insertdefinesuccesscount = 0;
        int insertdefineerrorcount = 0;

        //默认所有部门挂在华泰集团这个分部下
        String subcompanyid1 = OrganizationSynUtil.getSubcomIdByCode(HT0001);
        Map<String,String> map = new HashMap<String,String>();

        try{

            String response = OrganizationSynUtil.sendPost(url,"",headMap);
            JSONArray deptArray = JSONArray.parseArray(response);
            allcount = allcount + deptArray.size();
            for(int i=0;i<deptArray.size();i++)
            {
                JSONObject deptJson = deptArray.getJSONObject(i);
                String deptCode = Util.null2String(deptJson.getString("deptCode"));//部门编码
                String deptName = Util.null2String(deptJson.getString("deptName"));//部门名称
                String deptCodePath = Util.null2String(deptJson.getString("deptCodePath"));//部门编码
                String deptNamePath = Util.null2String(deptJson.getString("deptNamePath"));//部门名称路径
                String parentDeptCode = Util.null2String(deptJson.getString("parentDeptCode"));//上级部门编码
                String deptCity = Util.null2String(deptJson.getString("deptCity"),"null");//部门所在城市

                String deptTypeName = Util.null2String(deptJson.getString("deptTypeName"));//部门类型1名称
                String deptTypeCode = Util.null2String(deptJson.getString("deptTypeCode"));//部门类型1编码
                String deptType2Name = Util.null2String(deptJson.getString("deptType2Name"));//部门类型2名称
                String deptType2Code = Util.null2String(deptJson.getString("deptType2Code"));//部门类型2编码
                String deptDepth = Util.null2String(deptJson.getString("deptDepth"));//部门树所在深度
                String deptSortNum = Util.null2String(deptJson.getString("deptSortNum"));//部门排序编码
                String deptState = Util.null2String(deptJson.getString("deptState"));//部门状态

                String isActive = Util.null2String(deptJson.getString("isActive")); //
                if(!"ACTIVE".equals(isActive)){
                    deptState = "1";
                }
                String isLeafDept = "0";//是否没有子部门
                if(deptJson.getBoolean("isLeafDept"))
                {
                    isLeafDept = "1";
                }

                String deptScaleLevelCode = Util.null2String(deptJson.getString("deptScaleLevelCode"));//部门规模代码
                String deptScaleLevelName = Util.null2String(deptJson.getString("deptScaleLevelName"));//部门规模名称
                String departmentType = Util.null2String(deptJson.getString("departmentType"));//自定义部门类型
                departmentType = OrganizationSynUtil.getDepartmentType(departmentType);
                //String docNumAbbreviation = Util.null2String(deptJson.getString("docNumAbbreviation"));//部门简称
                //String docNumber = Util.null2String(deptJson.getString("docNumber"));//部门简称
                String cmpAbbre = Util.null2String(deptJson.getString("cmpAbbre"));//分公司简称

                String sysName = "";
                try{
                    sysName = Util.null2String(deptJson.getString("sysName"));//分公司简称
                }catch (Exception e){

                }

                bb.writeLog("deptCode:"+deptCode+"   sysName:"+sysName);
                if("TRIP".equalsIgnoreCase(sysName)){
                    deptState = "1";
                }

                //查询上级部门对应的ID
                String supDepid = null;
                if(!"".equals(parentDeptCode))
                {
                    supDepid =OrganizationSynUtil.getDeptIdByCode(parentDeptCode) +"";
                }

                if("".equals(supDepid) || supDepid==null){
                    supDepid="0";
                }
                try{
                    String deptId = OrganizationSynUtil.getDeptIdByCode(deptCode);
                    if(!"".equals(deptId)){ //更新部门数据
                        String deptUpdateSql =  " update hrmdepartment set departmentmark='"+deptName+"',departmentname='"+deptName+"',canceled='"+deptState+"'," +
                                " subcompanyid1='"+subcompanyid1+"',showorder='"+deptSortNum+"', supdepid='"+supDepid+"'  where departmentcode='"+deptCode+"' ";
                        bb.writeLog(deptUpdateSql);
                        boolean flag = rs.executeUpdate(deptUpdateSql);
                        if(flag)
                        {
                            updatesuccesscount++;
                        }else{
                            updateerrorcount++;
                        }
                    }else{ //插入部门数据

                        String deptNum = Util.null2String(deptJson.getString("deptNum"));
                        int intdeptNum = 0;
                        try{
                            if(!"".equals(deptNum)){
                                intdeptNum = Util.getIntValue(deptNum);
                            }else{
                                intdeptNum = -1;
                            }
                        }catch (Exception e){

                            bb.writeLog("OrganizationSyn-e:"+e);
                            intdeptNum = -2;
                        }

                        bb.writeLog(deptCode+":"+deptName+":"+"insert"+":"+isActive+":"+deptState+"deptNum:"+deptNum);

                        if(intdeptNum >0)
                        {
                            String deptInsertSql = " insert into hrmdepartment(id,departmentmark,departmentname,departmentcode," +
                                    " canceled,subcompanyid1,supdepid,showorder) values(?,?,?,?,?,?,?,?) ";
                            boolean flag =  rs.executeUpdate(deptInsertSql,new Object[]{intdeptNum+"",deptName,deptName,deptCode,deptState,subcompanyid1,supDepid,deptSortNum});
                            if(flag)
                            {
                                insertsuccesscount++;
                            }else{
                                inserterrorcount++;
                            }
                        }
                        //插入新部门后取部门id
                        deptId = OrganizationSynUtil.getDeptIdByCode(deptCode);
                    }

                    JSONArray departmentAreaManagers = deptJson.getJSONArray("departmentAreaManagers");//投行区域负责人
                    String txqyfzr = OrganizationSynUtil.getUserIdsByCodesObj(departmentAreaManagers); //主账号 多人
                    //更新部门自定义字段信息
                    String deptDefinedId = OrganizationSynUtil.getDeptDefineidByDeptid(deptId);
                    if(!"".equals(deptDefinedId))
                    {
                        String deptUpdateSql2 = " update hrmdepartmentdefined set deptCodePath='"+deptCodePath+"',deptNamePath='"+deptNamePath+"',deptCity='"+deptCity+"',deptTypeName='"+deptTypeName+"',deptTypeCode='"+deptTypeCode+"',deptType2Name='"+deptType2Name+"',deptType2Code='"+deptType2Code+"'," +
                                " deptDepth='"+deptDepth+"',isLeafDept='"+isLeafDept+"',deptScaleLevelCode='"+deptScaleLevelCode+"',deptScaleLevelName='"+deptScaleLevelName+"',departmentType='"+departmentType+"',cmpAbbre='"+cmpAbbre+"',txqyfzr='"+txqyfzr+"' where id='"+deptDefinedId+"' ";
                        bb.writeLog(deptUpdateSql2);
                        boolean flag = rs.executeUpdate(deptUpdateSql2);
                        if(flag)
                        {
                            insertdefinesuccesscount++;
                        }else{
                            insertdefineerrorcount++;
                        }
                    }else{
                        String deptInsertSql2 = " insert into hrmdepartmentdefined(deptid,deptCodePath,deptNamePath,deptCity," +
                                " deptTypeName,deptTypeCode,deptType2Name,deptType2Code,deptDepth,isLeafDept," +
                                " deptScaleLevelCode,deptScaleLevelName,departmentType,cmpAbbre,txqyfzr) " +
                                " values("+deptId+",'"+deptCodePath+"','"+deptNamePath+"','"+deptCity+"','"+ deptTypeName+"','"+deptTypeCode+"','"+deptType2Name+"','"+deptType2Code+"','"+deptDepth+"','"+isLeafDept+"','"+deptScaleLevelCode+"','"+deptScaleLevelName+"','"+departmentType+"','"+cmpAbbre+"','"+txqyfzr+"')";

                        boolean flag =  rs.execute(deptInsertSql2);
                        if(flag)
                        {
                            updatedefinesuccesscount++;
                        }else{
                            updatedefineerrorcount++;
                        }
                    }

//                    String deptabbrdefid = "" ;
//                    String sql = " select id from workflow_deptabbrdef where departmentid="+deptId;
//                    rs.execute(sql);
//                    if(rs.next()){
//                        deptabbrdefid = Util.null2String(rs.getString("id"));
//                    }
//                    if(!"".equals(deptabbrdefid)){
//                        sql = " update workflow_deptabbrdef set abbr='"+ docNumAbbreviation+"' where id="+deptabbrdefid ;
//                        rs.execute(sql);
//                    }else{
//                        sql = " insert into workflow_deptabbrdef(departmentid,abbr) values("+deptId+",'"+docNumAbbreviation+"') " ;
//                        rs.execute(sql);
//                    }
                }catch (Exception e){
                    bb.writeLog("OrganizationSyn-e:"+e);
                    e.printStackTrace();
                    exceptioncount++;
                    rs.writeLog("部门编号为"+deptCode+"的数据同步失败，data:"+deptJson.toJSONString());
                }
            }
        }catch (Exception e){
            bb.writeLog("OrganizationSyn-e:"+e);
        }

        map.put("allcount",allcount+"");

        map.put("updatesuccesscount",updatesuccesscount+"");
        map.put("updateerrorcount",updateerrorcount+"");
        map.put("insertsuccesscount",insertsuccesscount+"");
        map.put("inserterrorcount",inserterrorcount+"");

        map.put("updatedefinesuccesscount",updatedefinesuccesscount+"");
        map.put("updatedefineerrorcount",updatedefineerrorcount+"");
        map.put("insertdefinesuccesscount",insertdefinesuccesscount+"");
        map.put("insertdefineerrorcount",insertdefineerrorcount+"");

        map.put("exceptioncount",exceptioncount+"");

        return map;
    }


    /***
     * 部门同步
     * @param url
     */
    public Map<String,String> doDeptSynToLeader(String url,Map<String,String> headMap)
    {
        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();

        bb.writeLog("doDeptSynToLeader");
        int updatesuccesscount = 0;
        int updateerrorcount = 0;
        int exceptioncount = 0;
        int allcount = 0;

        Map<String,String> map = new HashMap<String,String>();
        try{
            String response = OrganizationSynUtil.sendPost(url,"",headMap);
            //默认所有部门挂在华泰集团这个分部下
            JSONArray deptArray = JSONArray.parseArray(response);

            allcount = allcount + deptArray.size();

            for(int i=0;i<deptArray.size();i++)
            {
                JSONObject deptJson = deptArray.getJSONObject(i);
                String deptCode = deptJson.getString("deptCode");//部门编码

                //部门HRBP转换对应人员的ID
                String deptHrBP = Util.null2String(deptJson.getString("deptHrBP"));//部门HRBP
                JSONArray deptHrBp2Arr = deptJson.getJSONArray("deptHrBp2");//部门HRBP2
                deptHrBp2Arr.add(deptHrBP);
                deptHrBP = OrganizationSynUtil.getUserIdsByCodes(deptHrBp2Arr);  //住账号 多人

                String deptMP = Util.null2String(deptJson.getString("deptMP"));//部门内勤
                deptMP = OrganizationSynUtil.getUserIdByCode(deptMP);  //主账号

                JSONArray deptDirectorsArr = deptJson.getJSONArray("deptDirectors");//部门负责人

                JSONArray deptLeadersArr = deptJson.getJSONArray("deptLeaders");//部门分管领导
                String deptLeaders = OrganizationSynUtil.getUserIdsByCodesObj(deptLeadersArr); //主账号 多人
                bb.writeLog("deptCode:"+deptCode+" deptLeadersArr:"+deptLeadersArr +" deptLeaders:"+deptLeaders);
                String txqyfzr = "" ;
                try{
                    JSONArray departmentAreaManagers = deptJson.getJSONArray("departmentAreaManagers");//投行区域负责人
                    txqyfzr = OrganizationSynUtil.getUserIdsByCodesObj(departmentAreaManagers); //主账号 多人
                }catch (Exception e){
                    bb.writeLog("OrganizationSyn-e:"+e);
                }

                String deptNum = Util.null2String(deptJson.getString("deptNum")); //部门ID
                int intdeptNum = 0;
                try{
                    if(!"".equals(deptNum)){
                        intdeptNum = Util.getIntValue(deptNum);
                    }else{
                        intdeptNum = -1;
                    }
                }catch (Exception e){
                    bb.writeLog("OrganizationSyn-e:"+e);
                    intdeptNum = -2;
                }
                if(intdeptNum >0){
                    try{
                        String deptDirectors = OrganizationSynUtil.getUserIdsByCodes2Dept(deptDirectorsArr);
                        String cohead = OrganizationSynUtil.getCohead(deptDirectorsArr);
                        String deptId = OrganizationSynUtil.getDeptIdByCode(deptCode);

                        //更新部门自定义字段信息
                        if(!"".equals(deptId))
                        {
                            String deptDefinedId = OrganizationSynUtil.getDeptDefineidByDeptid(deptId);
                            if(!"".equals(deptDefinedId))
                            {
                                bb.writeLog(deptDefinedId+":"+deptLeaders+":"+deptHrBP+":"+deptMP+":"+deptDirectors+":"+txqyfzr+" :update");
                                String deptUpdateSql = " update hrmdepartmentdefined set deptHrBP=?,deptMP=?,deptDirectors=?,deptLeaders=?,cohead=?,txqyfzr=? where id=? ";
                                boolean flag1 = rs.executeUpdate(deptUpdateSql,new Object[]{deptHrBP,deptMP,deptDirectors,deptLeaders,cohead,txqyfzr,deptDefinedId});
                                if(flag1){
                                    updatesuccesscount++;
                                }else{
                                    updateerrorcount++;
                                }
                            }
                        }
                    }catch (Exception e){
                        bb.writeLog("OrganizationSyn-e:"+e);
                        exceptioncount++;
                        rs.writeLog("部门编号为"+deptCode+"的数据同步失败，data:"+deptJson.toJSONString());
                    }
                }
            }
        }catch (Exception e){
            bb.writeLog("OrganizationSyn-e:"+e);
        }

        map.put("updatesuccesscount",updatesuccesscount+"");
        map.put("updateerrorcount",updateerrorcount+"");
        map.put("exceptioncount",exceptioncount+"");
        map.put("allcount",allcount+"");
        return map;
    }


    /***
     *
     * @param url
     */
    public Map<String,String> doHrmSyn(String url,Map<String,String> headMap)
    {
        BaseBean bb = new BaseBean();
        PropBean pb = new PropBean();
        RecordSet rs = new RecordSet();
        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        int updatesuccesscount = 0;
        int updateerrorcount = 0;
        int insertsuccesscount = 0;
        int inserterrorcount = 0;
        int exceptioncount = 0;
        int dataerrorcount = 0;

        Map<String,String> map = new HashMap<String,String>();

        String HT0001 = pb.getPropName("HT0001");
        String subcompanyid1 = OrganizationSynUtil.getSubcomIdByCode(HT0001);

        int page = 0;
        int pageSize = 300;
        int allcount = 0;
        int allyxcount = 0;
        boolean hasNextPage = true;
        while(hasNextPage)
        {
            String response = "" ;
            try{
                String urlnew = url+"?page="+page+"&size="+pageSize;
                bb.writeLog("page:"+page+" size:"+pageSize);
                response = OrganizationSynUtil.sendPost(urlnew,"",headMap);
            }catch (Exception e){
                bb.writeLog("OrganizationSyn-e:"+e);
            }

            if(response !="" && !"".equals(response))
            {
                try{
                    JSONArray userArray = JSONArray.parseArray(response);
                    allcount = allcount + userArray.size() ;
                    for(int i=0;i<userArray.size();i++)
                    {
                        JSONObject userJson = userArray.getJSONObject(i);
                        String empCode = Util.null2String(userJson.getString("empCode"));//员工编号
                        bb.writeLog("empCode:"+empCode);
                        try{
                            String empName = Util.null2String(userJson.getString("empName"));//员工姓名

                            String empGender = Util.null2String(userJson.getString("empGender"));//员工性别
                            if("女".equals(empGender)){
                                empGender = "1";
                            }else{
                                empGender = "0";
                            }
                            String field1 = "";//微信大头像
                            String field2 = "";//微信小头像
                            String field0 = Util.null2String(userJson.getString("city"));//工作城市
                            String field8 = Util.null2String(userJson.getString("empEngName"));//员工英文名

                            String creator = Util.null2String(userJson.getString("creator"));//创建者工号
                            creator = OrganizationSynUtil.getUserIdByCode(creator);  //主账号
                            if("".equals(creator)){
                                creator = "1";
                            }

                            String accentEmail = Util.null2String(userJson.getString("accentEmail"));//主要邮箱
                            String accentMobile = Util.null2String(userJson.getString("accentMobile"));//主要手机
                            String accentPhone = Util.null2String(userJson.getString("accentPhone"));//主要座机

                            String field3 = Util.null2String(userJson.getString("empEmails"));//员工EMAIL
                            if(!"".equals(field3)){
                                field3 = field3.replace("[","").replace("]","").replace("\"","");
                            }

                            String field4 = Util.null2String(userJson.getString("empMobiles"));//员工手机号
                            if(!"".equals(field4)){
                                field4 = field4.replace("[","").replace("]","").replace("\"","");
                            }

                            String field5 = Util.null2String(userJson.getString("empPhones"));//员工固话
                            if(!"".equals(field5)){
                                field5 = field5.replace("[","").replace("]","").replace("\"","");
                            }

                            String userState = Util.null2String(userJson.getString("userState"));//用户状态
                            int empSortNum = (0- Util.getIntValue(userJson.getString("empSortNum"),0));//员工排序号
                            String field6 =  Util.null2String(userJson.getString("state"));//是否是外部联系人
                            String field7 =  Util.null2String(userJson.getString("comment"));//备注

                            String field9 = Util.null2String(userJson.getString("empJobGrade"));//员工职级
                            String field11 = Util.null2String(userJson.getString("empRealWorkCity"));//员工职级

                            String currentDate = TimeUtil.getCurrentDateString();//当前日期
                            String deptId = "";
                            String jobTitleId = "";
                            String textfield2 = "" ;
                            //同步主岗数据
                            JSONObject primaryPosition = userJson.getJSONObject("primaryPosition");//主岗信息
                            String empPositionNum = "" ;
                            if(primaryPosition!=null)
                            {
                                OrganizationSynUtil.doJobTitleSyn(primaryPosition);
                                String deptCode = primaryPosition.getString("deptCode");
                                empPositionNum = primaryPosition.getString("empPositionNum");
                                if(!"".equals(deptCode))
                                {
                                    deptId = OrganizationSynUtil.getDeptIdByCode(deptCode);
                                }
                                String positionCode = primaryPosition.getString("positionCode");
                                if(!"".equals(deptId) && !"".equals(positionCode)){
                                    jobTitleId = OrganizationSynUtil.getJobTitleIdByCode(positionCode,deptId);
                                }
                                textfield2 = deptCode+";"+positionCode+";"+empCode;
                            }

                            bb.writeLog("textfield2:"+textfield2);

                            if("ACTIVE".equalsIgnoreCase(userState)){
                                userState = "1";
                            }else{
                                userState = "5";
                            }

                            String userId = OrganizationSynUtil.getUserIdByCode(empCode);  //主账号
                            if(!"".equals(deptId) && !"".equals(jobTitleId))
                            {
                                if(!"".equals(userId))
                                {
                                    //人员已存在，更新操作
                                    String userUpdateSql1 = " update hrmresource set lastname='"+empName+"',departmentid='"+deptId+"',subcompanyid1='"+subcompanyid1+"',sex='"+empGender+"'," +
                                            " creater='"+creator+"',email='"+accentEmail+"',mobile='"+accentMobile+"',telephone='"+accentPhone+"',jobtitle='"+jobTitleId+"',status='"+userState+"',dsporder='"+empSortNum+"',lastmoddate='"+currentDate+"',modified=systimestamp,textfield2='"+textfield2+"' where id = '"+userId+"' ";
                                    boolean flag = rs.executeUpdate(userUpdateSql1);
                                    if(flag)
                                    {
                                        long intresourceNum = 0;
                                        try{
                                            if(!"".equals(empPositionNum) && !"null".equals(empPositionNum) && empPositionNum !=null){
                                                intresourceNum = Long.parseLong(empPositionNum);
                                            }else{
                                                intresourceNum = -1;
                                            }
                                        }catch (Exception e){
                                            bb.writeLog("OrganizationSyn-e:"+e);
                                            intresourceNum = -2;
                                        }
                                        if(intresourceNum >0)
                                        {
                                            try{

                                                if(!userId.equals(intresourceNum))
                                                {
                                                    String sql = " update hrmresource set id="+intresourceNum+" where id="+userId ;
                                                    boolean isup = rs.executeUpdate(sql);
                                                    if(isup)
                                                    {
                                                        int cusFielddataId = OrganizationSynUtil.getCusFielddataId(intresourceNum+"",1);
                                                        if(cusFielddataId>0){
                                                            String userUpdateSql2 = " update cus_fielddata set field0=?,field1=?,field2=?,field3=?,field4=?," +
                                                                    " field5=?,field6=?,field7=?,field8=?,field9=?,field11=? where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=?";
                                                            bb.writeLog(userUpdateSql2);
                                                            rs.executeUpdate(userUpdateSql2,new Object[]{field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,field11,intresourceNum});
                                                        }else{
                                                            String userInsertSql2 = " insert into cus_fielddata(scope,scopeid,id,field0,field1,field2,field3," +
                                                                    " field4,field5,field6,field7,field8,field9,field11) values('HrmCustomFieldByInfoType',1,?,?,?,?,?,?,?,?,?,?,?,?)";
                                                            rs.executeUpdate(userInsertSql2,new Object[]{intresourceNum,field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,field11});
                                                        }
                                                    }
                                                }
                                            }catch (Exception e){
                                                bb.writeLog("OrganizationSyn-e:"+e);
                                            }
                                        }

                                        updatesuccesscount++;

                                    }else{
                                        updateerrorcount++;
                                    }
                                }else{
                                    //人员不存在，插入操作

                                    String dynapass = Util.null2String(pb.getPropName( "PASSWORD"),"Ht123456!");
                                    String[] pwdArr = PasswordUtil.encrypt(dynapass);
                                    String newPWD= pwdArr[0];


                                    long intresourceNum = 0;
                                    try{
                                        if(!"".equals(empPositionNum) && !"null".equals(empPositionNum) && empPositionNum !=null){
                                            intresourceNum = Long.parseLong(empPositionNum);
                                        }else{
                                            intresourceNum = -1;
                                        }
                                    }catch (Exception e){
                                        bb.writeLog("OrganizationSyn-e:"+e);
                                        intresourceNum = -2;
                                    }

                                    if(intresourceNum >0)
                                    {
                                        rs.executeProc("HrmResourceMaxId_Get","");
                                        rs.next();
                                        userId = rs.getInt(1)+"";

                                        String userInsertSql1 = " insert into hrmresource(id,loginid,password,workcode,lastname,departmentid,subcompanyid1,sex," +
                                                " creater,email,mobile,telephone,jobtitle,status,dsporder,systemlanguage,createdate,lastmoddate," +
                                                " created,modified,textfield2) " +
                                                " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,systimestamp,systimestamp,?)";

                                        boolean flag = rs.executeUpdate(userInsertSql1,new Object[]{userId,empCode,newPWD,empCode,empName,deptId,subcompanyid1,empGender,
                                                creator,accentEmail,accentMobile,accentPhone,jobTitleId,userState,empSortNum,7,currentDate,currentDate,textfield2});
                                        if(flag)
                                        {
                                            insertsuccesscount++;
                                            try{
                                                String sql = " update hrmresource set id="+intresourceNum+" where id="+userId ;
                                                boolean isup = rs.executeUpdate(sql);
                                                if(isup)
                                                {
                                                    int cusFielddataId = OrganizationSynUtil.getCusFielddataId(intresourceNum+"",1);
                                                    if(cusFielddataId>0){
                                                        String userUpdateSql2 = " update cus_fielddata set field0=?,field1=?,field2=?,field3=?,field4=?," +
                                                                " field5=?,field6=?,field7=?,field8=?,field9=?,field11=? where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=?";
                                                        bb.writeLog(userUpdateSql2);
                                                        rs.executeUpdate(userUpdateSql2,new Object[]{field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,field11,intresourceNum});
                                                    }else{
                                                        String userInsertSql2 = " insert into cus_fielddata(scope,scopeid,id,field0,field1,field2,field3," +
                                                                " field4,field5,field6,field7,field8,field9,field11) values('HrmCustomFieldByInfoType',1,?,?,?,?,?,?,?,?,?,?,?,?)";
                                                        rs.executeUpdate(userInsertSql2,new Object[]{intresourceNum,field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,field11});
                                                    }
                                                }
                                            }catch (Exception e){
                                                bb.writeLog("OrganizationSyn-e:"+e);
                                            }
                                        }else{
                                            inserterrorcount++;
                                        }
                                    }
                                }
                            }else{
                                dataerrorcount++;
                            }
                        }catch (Exception e){
                            e.printStackTrace();
                            bb.writeLog("OrganizationSyn-e:"+e);
                            rs.writeLog("人员编号"+empCode+"的数据同步失败，data:"+userJson.toJSONString());
                            exceptioncount ++ ;
                        }
                    }
                    if(userArray.size()<pageSize)
                    {
                        hasNextPage = false;
                    }
                }catch (Exception e){
                    bb.writeLog("OrganizationSyn-e:"+e);
                }

                page++;
            }else{
                bb.writeLog("777777777777777");
                hasNextPage = false;
            }
        }

        bb.writeLog("##################allcount:"+allcount);
        map.put("updatesuccesscount",updatesuccesscount+"");
        map.put("updateerrorcount",updateerrorcount+"");
        map.put("insertsuccesscount",insertsuccesscount+"");
        map.put("inserterrorcount",inserterrorcount+"");
        map.put("exceptioncount",exceptioncount+"");
        map.put("dataerrorcount",dataerrorcount+"");
        map.put("allcount",allcount+"");
        return map;
    }

    /***
     *
     * @param url
     */
    public void doHrmSynPhoto(String url,Map<String,String> headMap)
    {

        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        RecordSet rs = new RecordSet();
        int page = 0;
        int pageSize = 300;
        boolean hasNextPage = true;
        BaseBean bb = new BaseBean();
        while(hasNextPage)
        {
            String urlnew = url+"?page="+page+"&size="+pageSize;
            bb.writeLog("page:"+page);
            String response = OrganizationSynUtil.sendPost(urlnew,"",headMap);
            if(!"".equals(response))
            {
                JSONArray userArray = JSONArray.parseArray(response);
                for(int i=0;i<userArray.size();i++)
                {
                    JSONObject userJson = userArray.getJSONObject(i);
                    String empCode = Util.null2String(userJson.getString("empCode"));//员工编号
                    try{
                        String userState = Util.null2String(userJson.getString("userState"));//用户状态
                        String userId = OrganizationSynUtil.getUserIdByCode(empCode);  //主账号
                        if("ACTIVE".equalsIgnoreCase(userState))
                        {
                            String photo = Util.null2String(userJson.getString("photo"));
                            synHrmPhoto(empCode,photo,userId);
                        }
                    }catch (Exception e){
                        bb.writeLog("OrganizationSyn-e:"+e);
                        e.printStackTrace();
                        rs.writeLog("人员编号"+empCode+"的数据同步失败，data:"+userJson.toJSONString());
                    }
                }

                if(userArray.size()<pageSize)
                {
                    hasNextPage = false;
                }
                page++;

            }else{
                hasNextPage = false;
            }
        }
    }

    /***
     *
     * @param empCode
     * @param photo
     * @param userId
     */
    public void synHrmPhoto(String empCode,String photo,String userId){
        String rootpath = GCONST.getRootPath(); // "/app/ecology";
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        // rs.writeLog("synHrmPhoto:empCode:"+empCode+"userId:"+userId);
        try{
            if(!"".equals(empCode) && empCode !=null)
            {
                // /app/ecology/messager/usericon/001553/001553.jpg
                // /htoa/messager/usericon/012901/012901.jpg

                String attachfilename = empCode+".jpg";
                String imagefiletype = "image/jpeg" ;
                String usericonpath = "filesystem/messager/usericon/"+ empCode;

                String usericonrealpath = rootpath+usericonpath;

                String usericonurl = "/htoa/"+usericonpath+"/"+attachfilename ;

                String usericonrealurl = rootpath+usericonpath+"/"+attachfilename ;

                File iconpath = new File(usericonrealpath);
                if (!iconpath.exists())
                {
                    iconpath.mkdirs();
                }
                if(!"".equals(photo) && photo !=null)
                {
                    boolean flag = base64ToImage(photo,usericonrealurl);
                    if(flag)
                    {
                        String resourceimageid = "" ;
                        String sql = " select resourceimageid from hrmresource where id="+userId ;
                        rs.execute(sql);
                        if(rs.next()){
                            resourceimageid = Util.null2String(rs.getString("resourceimageid"));
                        }
                        if(!"".equals(resourceimageid))
                        {
                            String imagefileidold = "" ;
                            sql = " select filerealpath,imagefileid from ImageFile where imagefileid="+resourceimageid;
                            rs.execute(sql);
                            if(rs.next()){
                                imagefileidold = Util.null2String(rs.getString("imagefileid"));
                            }
                            if(!"".equals(imagefileidold))
                            {
                                sql = " update ImageFile set filerealpath='"+usericonrealurl+"' where imagefileid ="+imagefileidold+"" ;
                                rs.writeLog("sql:"+sql);
                                rs.execute(sql);

                                if(!"".equals(userId))
                                {
                                    String fileid = "";
                                    try{
                                        fileid = DocDownloadCheckUtil.checkPermission(imagefileidold,null);
                                    }catch (Exception e){
                                        bb.writeLog("OrganizationSyn-e:"+e);
                                    }
                                    String fileurl = "/htoa/weaver/weaver.file.FileDownload?fileid="+fileid;
                                    sql = " update hrmresource set messagerurl='"+fileurl+"' where workcode='"+empCode+"'" ;
                                    rs.writeLog("sql:"+sql);
                                    rs.execute(sql);
                                }
                            }else{
                                ImageFileIdUpdate im = new ImageFileIdUpdate();
                                int imagefileid = im.getImageFileNewId();
                                rs.writeLog("imagefileid:"+imagefileid);
                                sql= " insert into ImageFile(imagefileid,imagefilename,imagefiletype,imagefileused,filerealpath,iszip,isencrypt,fileSize) "+
                                        " values("+imagefileid+",'"+attachfilename+"','"+imagefiletype+"',1,'"+usericonrealurl+"',0,0,'"+photo.length()+"')";
                                rs.execute(sql);

                                if(!"".equals(userId))
                                {
                                    String fileid = "";
                                    try{
                                        fileid = DocDownloadCheckUtil.checkPermission(imagefileid+"",null);
                                    }catch (Exception e){
                                        bb.writeLog("OrganizationSyn-e:"+e);
                                    }

                                    String fileurl = "/htoa/weaver/weaver.file.FileDownload?fileid="+fileid;
                                    sql = " update hrmresource set resourceimageid="+imagefileid+",messagerurl='"+fileurl+"' where workcode='"+empCode+"'" ;
                                    rs.writeLog("sql:"+sql);
                                    rs.execute(sql);
                                }
                            }
                        }else{
                            ImageFileIdUpdate im = new ImageFileIdUpdate();
                            int imagefileid = im.getImageFileNewId();
                            rs.writeLog("imagefileid:"+imagefileid);
                            rs.writeLog("imagefileid:"+imagefileid);
                            sql= " insert into ImageFile(imagefileid,imagefilename,imagefiletype,imagefileused,filerealpath,iszip,isencrypt,fileSize) "+
                                    " values("+imagefileid+",'"+attachfilename+"','"+imagefiletype+"',1,'"+usericonrealurl+"',0,0,'"+photo.length()+"')";
                            rs.writeLog("sql:"+sql);
                            rs.execute(sql);

                            if(!"".equals(userId))
                            {
                                String fileid = "";
                                try{
                                    fileid = DocDownloadCheckUtil.checkPermission(imagefileid+"",null);
                                }catch (Exception e){
                                    bb.writeLog("OrganizationSyn-e:"+e);
                                }

                                String fileurl = "/htoa/weaver/weaver.file.FileDownload?fileid="+fileid;
                                sql = " update hrmresource set resourceimageid="+imagefileid+",messagerurl='"+fileurl+"' where workcode='"+empCode+"'" ;
                                rs.writeLog("sql:"+sql);
                                rs.execute(sql);
                            }
                        }
                    }else{
                        bb.writeLog(empCode+": no Photo22222");
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            bb.writeLog("OrganizationSyn-e:"+e);
        }
    }

    /**
     * @Descriptionmap 对字节数组字符串进行Base64解码并生成图片
     * @author temdy
     * @Date 2015-01-26
     * @param base64 图片Base64数据
     * @param path 图片路径
     * @return
     */
    public boolean base64ToImage(String base64,String path) {// 对字节数组字符串进行Base64解码并生成图片
        if (base64 == null) { // 图像数据为空
            return false;
        }
        BaseBean bb = new BaseBean();
        bb.writeLog("path:"+path);
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            // Base64解码
            byte[] bytes = decoder.decodeBuffer(base64);
            for (int i = 0; i < bytes.length; ++i) {
                if (bytes[i] < 0) {// 调整异常数据
                    bytes[i] += 256;
                }
            }
            // 生成jpeg图片
            OutputStream out = new FileOutputStream(path);
            out.write(bytes);
            out.flush();
            out.close();
            return true;
        } catch (Exception e) {
            bb.writeLog("OrganizationSyn-e:"+e);
            return false;
        }
    }




    /***
     * 同步岗位数据及此账号
     */
    public Map<String,String> doPositionSyn(String url,Map<String,String> headMap)
    {

        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        Map<String,String> map = new HashMap<String,String>();
        BaseBean bb = new BaseBean();
        bb.writeLog("------doPositionSyn-------");
        int updatesuccesscount = 0;
        int updateerrorcount = 0;
        int insertsuccesscount = 0;
        int inserterrorcount = 0;
        int exceptioncount = 0;
        int dataerrorcount = 0;
        int allcount = 0;
        String message = "";
        int nullcount = 0;
        try{
            int page = 0;
            int pageSize = 300;
            boolean hasNextPage = true;
            while (hasNextPage) {
                try{
                    String urlnew = url+"?page=" + page + "&size=" + pageSize;
                    bb.writeLog("page:"+page+" size:"+pageSize);
                    String response = OrganizationSynUtil.sendPost(urlnew, "", headMap);
                    JSONArray positionArray = JSONArray.parseArray(response);
                    allcount = allcount + positionArray.size();

                    for (int i = 0; i < positionArray.size(); i++)
                    {
                        try{
                            JSONObject positionJson = positionArray.getJSONObject(i);
                            String positionType = Util.null2String(positionJson.get("positionType"));
                            OrganizationSynUtil.doJobTitleSyn(positionJson);
                            if("0".equals(positionType))
                            {
                                //住账号的岗位数据同步
                                int count = doMainAccountSynTime(positionJson);
                                if(count == 1){
                                    updatesuccesscount++;
                                }else if(count == -1){
                                    updateerrorcount++;
                                }else if(count == -3){
                                    dataerrorcount++;
                                }else if(count == -2){
                                    exceptioncount++;
                                }
                            }else{
                                allcount++;
                                //次账号的岗位数据同步
                                int count = doSecAccountSynTime(positionJson);
                                if(count == 1){
                                    updatesuccesscount++;
                                }else if(count == 2){
                                    insertsuccesscount++;
                                }else if(count == -10){
                                    updateerrorcount++;
                                }else if(count == -11){
                                    inserterrorcount++;
                                }else if(count == -3){
                                    dataerrorcount++;
                                }else if(count == -2){
                                    exceptioncount++;
                                }else if(count == -100){
                                    nullcount++;
                                }
                            }
                        }catch (Exception e){

                            bb.writeLog("OrganizationSyn-e:"+e);
                        }
                    }
                    if (positionArray.size() < pageSize) {
                        hasNextPage = false;
                    }
                }catch (Exception e){
                    bb.writeLog("OrganizationSyn-e:"+e);
                }
                page++;
            }
            bb.writeLog("###############allcount:"+allcount);
        }catch (Exception e){
            bb.writeLog("OrganizationSyn-e:"+e);
            message = e.getMessage();
        }

        bb.writeLog("nullcount:"+nullcount);
        map.put("updatesuccesscount",updatesuccesscount+"");
        map.put("updateerrorcount",updateerrorcount+"");
        map.put("insertsuccesscount",insertsuccesscount+"");
        map.put("inserterrorcount",inserterrorcount+"");
        map.put("exceptioncount",exceptioncount+"");
        map.put("allcount",allcount+"");
        map.put("message",message);

        return map;
    }


    /****
     *
     * @param url
     * @return
     */
    public Map<String,String> doAbsPositionSyn(String url,Map<String,String> headMap)
    {
        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        Map<String,String> map = new HashMap<String,String>();
        BaseBean bb = new BaseBean();
        bb.writeLog("------doAbsPositionSyn-------");
        int updatesuccesscount = 0;
        int updateerrorcount = 0;
        int insertsuccesscount = 0;
        int inserterrorcount = 0;
        int exceptioncount = 0;
        int dataerrorcount = 0;

        int nullcount = 0;
        try{
            String response = OrganizationSynUtil.sendPost(url, "", headMap);
            JSONArray positionArray = JSONArray.parseArray(response);
            for (int i = 0; i < positionArray.size(); i++)
            {
                try{
                    JSONObject positionJson = positionArray.getJSONObject(i);
                    String positionType = Util.null2String(positionJson.get("positionType"));
                    OrganizationSynUtil.doJobTitleSyn(positionJson);

                    if("0".equals(positionType))
                    {
                        bb.writeLog("doAbsPositionSyn-----positionType:"+positionType);
                        //住账号的岗位数据同步
                        int count = doMainAccountSynTime(positionJson);
                        if(count == 1){
                            updatesuccesscount++;
                        }else if(count == -1){
                            updateerrorcount++;
                        }else if(count == -3){
                            dataerrorcount++;
                        }else if(count == -2){
                            exceptioncount++;
                        }
                    }else{
                        //次账号的岗位数据同步
                        int count = doSecAccountSynTime(positionJson);


                        if(count == 1){
                            updatesuccesscount++;
                        }else if(count == 2){
                            insertsuccesscount++;
                        }else if(count == -10){
                            updateerrorcount++;
                        }else if(count == -11){
                            inserterrorcount++;
                        }else if(count == -3){
                            dataerrorcount++;
                        }else if(count == -2){
                            exceptioncount++;
                        }else if(count == -100){
                            nullcount++;
                        }
                    }
                }catch (Exception e){

                    bb.writeLog("OrganizationSyn-e:"+e);
                }
            }
        }catch (Exception e){

            bb.writeLog("OrganizationSyn-e:"+e);
        }

        bb.writeLog("nullcount:"+nullcount);
        map.put("updatesuccesscount",updatesuccesscount+"");
        map.put("updateerrorcount",updateerrorcount+"");
        map.put("insertsuccesscount",insertsuccesscount+"");
        map.put("inserterrorcount",inserterrorcount+"");
        map.put("exceptioncount",exceptioncount+"");
        return map;
    }


    /**
     *
     * @param userJson
     */
    public int doMainAccountSynTime(JSONObject userJson)
    {
        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        int count = 0;
        BaseBean bb = new BaseBean();
        PropBean pb = new PropBean();
        RecordSet rs = new RecordSet();
        String HT0001 = pb.getPropName("HT0001");

        try{
            String subcompanyid1 = OrganizationSynUtil.getSubcomIdByCode(HT0001);

            if(userJson !=null)
            {
                String empCode = Util.null2String(userJson.getString("empCode"));//员工编号
                String positionCode = Util.null2String(userJson.getString("positionCode"));//员工编号
                String deptCode = Util.null2String(userJson.getString("deptCode"));//员工编号
                String strsafeLevel = Util.null2String(userJson.getString("safeLevel"));
                int safeLevel = 0;
                if(!"".equals(strsafeLevel)){
                    safeLevel = Util.getIntValue(strsafeLevel);//安全级别
                }
                bb.writeLog("empCode:"+empCode+" deptCode:"+deptCode+" positionCode:"+positionCode+"&strsafeLevel:"+strsafeLevel);

                String empRealWorkCity = Util.null2String(userJson.getString("empRealWorkCity"));

                if(!"".equals(positionCode) && !"".equals(deptCode))
                {
                    String deptId = OrganizationSynUtil.getDeptIdByCode(deptCode);
                    String jobTitleId = OrganizationSynUtil.getJobTitleIdByCode(positionCode,deptId);
                    String jobState = Util.null2String(userJson.getString("jobState"));//员工编号
                    if("ACTIVE".equalsIgnoreCase(jobState))
                    {
                        jobState = "1";
                    }else{
                        jobState = "5";
                    }
                    String textfield2 = deptCode+";"+positionCode+";"+empCode;

                    String userId = OrganizationSynUtil.getUserIdByCode(empCode);
                    if(!"".equals(userId))
                    {
                        //人员已存在，更新操作
                        String userUpdateSql1 = " update hrmresource set departmentid='"+deptId+"',subcompanyid1='"+subcompanyid1+"',jobtitle='"+jobTitleId+"',status='"+jobState+"',textfield2='"+textfield2+"',seclevel='"+safeLevel+"'  where id='"+userId+"'";
                        bb.writeLog(userUpdateSql1);
                        boolean flag = rs.executeUpdate(userUpdateSql1);
                        if(flag)
                        {
                            count = 1;

                            String userDataSql = " update cus_fielddata set field11='"+empRealWorkCity+"' where id in(select id from hrmresource where workcode='"+empCode+"' and status=1) and scopeid=1 and scope='HrmCustomFieldByInfoType'";
                            rs.execute(userDataSql);
                        }else{
                            count = -1;
                        }
                    }
                }else
                {
                    count = -3;
                }
            }
        }catch (Exception e){
            bb.writeLog("OrganizationSyn-e:"+e);
            count = -2;
        }
        return count;
    }

    /**
     * 次账号同步
     * @param positionJson
     */
    public int doSecAccountSynTime(JSONObject positionJson){
        int count = 0;

        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        BaseBean bb = new BaseBean();
        PropBean pb = new PropBean();
        String HT0001 = pb.getPropName("HT0001");

        bb.writeLog("------doSecAccountSynTime------");
        try{
            if(positionJson!=null)
            {
                RecordSet rs = new RecordSet();
                String subcompanyid1 = OrganizationSynUtil.getSubcomIdByCode(HT0001);
                String uuid = Util.null2String(positionJson.getString("uuid"));
                String empCode = Util.null2String(positionJson.getString("empCode"));
                String empName = Util.null2String(positionJson.getString("empName"));
                String deptCode = Util.null2String(positionJson.getString("deptCode"));
                String positionCode = Util.null2String(positionJson.getString("positionCode"));

                int safeLevel = 0;
                String strsafeLevel = Util.null2String(positionJson.getString("safeLevel"));
                if(!"".equals(strsafeLevel)){
                    safeLevel = Util.getIntValue(positionJson.getString("safeLevel"));//安全级别
                }

                bb.writeLog("empCode:"+empCode+" deptCode:"+deptCode+" positionCode:"+positionCode+" strsafeLevel："+strsafeLevel);

                String empPositionNum = Util.null2String(positionJson.getString("empPositionNum"));

//                String empRealWorkCity = Util.null2String(positionJson.getString("empRealWorkCity"));
//                bb.writeLog("empRealWorkCity:"+empRealWorkCity);

                if(!"".equals(empCode))
                {
                    String belongto = OrganizationSynUtil.getUserIdByCode(empCode);
                    String deptId = OrganizationSynUtil.getDeptIdByCode(deptCode);
                    if(!"".equals(deptId) && !"".equals(positionCode))
                    {
                        String jobTitleId = OrganizationSynUtil.getJobTitleIdByCode(positionCode,deptId);
                        String jobState = Util.null2String(positionJson.getString("jobState"));
                        if("ACTIVE".equalsIgnoreCase(jobState)){
                            jobState = "1";
                        }else{
                            jobState = "5";
                        }

                        String currentDate = TimeUtil.getCurrentDateString();//当前日期
                        String textfield2 = deptCode+";"+positionCode+";"+empCode;


                        String sex = "" ;
                        String seclevel = safeLevel+"";
                        int dsporder = 0;
                        String password = "" ;
                        String messagerurl = "";
                        String resourceimageid = "";

                        //查询主账号的信息
                        String mainUserId = "";
                        rs.executeQuery(" select * from hrmresource where workcode='"+empCode+"' and belongto is null and status=1 ");
                        if(rs.next())
                        {
                            mainUserId = Util.null2String(rs.getString("id"));
                            sex = Util.null2String(rs.getString("sex"));
                            dsporder = Util.getIntValue(Util.null2String(rs.getString("dsporder")), 0);
                            messagerurl = Util.null2String(rs.getString("resourceimageid"));
                            resourceimageid = Util.null2String(rs.getString("resourceimageid"));
                        }

                        String field1 = "";//微信大头像
                        String field2 = "";//微信小头像
                        String field0 = "";//工作城市
                        String field3 = ""; //员工EMAIL
                        String field4 = ""; //员工手机号
                        String field5 = ""; //员工固话
                        String field6 =  ""; //是否是外部联系人
                        String field7 =  "";//备注
                        String field8 = "";//员工英文名
                        String field9 = ""; //员工职级
                        String field11 = "";//真实工作地
                        rs.executeQuery(" select * from cus_fielddata where scopeid=1 and id= "+mainUserId);
                        if(rs.next())
                        {
                            field0 = Util.null2String(rs.getString("field0"));
                            field3 = Util.null2String(rs.getString("field3"));
                            field4 = Util.null2String(rs.getString("field4"));
                            field5 = Util.null2String(rs.getString("field5"));
                            field6 = Util.null2String(rs.getString("field6"));
                            field7 = Util.null2String(rs.getString("field7"));
                            field8 = Util.null2String(rs.getString("field8"));
                            field9 = Util.null2String(rs.getString("field9"));
                            field11 = Util.null2String(rs.getString("field11"));
                        }

                        String userId = getSecAccountIdByTextfield2(textfield2);
                        if (!"".equals(userId))
                        {
                            //bb.writeLog(empCode+":"+userId+":doSecAccountSynTime:update : "+dsporder+":"+jobState);
                            String userUpdateSql =  " update hrmresource set lastname='"+empName+"',departmentid='"+deptId+"',subcompanyid1='"+subcompanyid1+"',sex='"+sex+"'," +
                                    " jobtitle='"+jobTitleId+"',status='"+jobState+"',lastmoddate='"+currentDate+"',modified=systimestamp,dsporder='"+dsporder+"',textfield1='"+uuid+"',textfield2='"+textfield2+"',workcode='"+empCode+"',seclevel='"+seclevel+"',messagerurl='"+messagerurl+"',resourceimageid='"+resourceimageid+"' where id='"+userId+"' ";

                            bb.writeLog("userUpdateSql:"+userUpdateSql);
                            boolean flag = rs.executeUpdate(userUpdateSql);
                            if(flag){
                                count = 1;
                                if("5".equals(jobState))
                                {
                                    bb.writeLog("com.api.customization.workflow.biz.ResignAgentBiz().agentOutRequest---userId:"+userId);
                                    Util.getIntValue(userId);
                                }

                                long intresourceNum = 0;
                                try{
                                    if(!"".equals(empPositionNum) && !"null".equals(empPositionNum) && empPositionNum !=null){
                                        intresourceNum = Long.parseLong(empPositionNum);
                                    }else{
                                        intresourceNum = -1;
                                    }
                                }catch (Exception e){
                                    bb.writeLog("OrganizationSyn-e:"+e);
                                    intresourceNum = -2;
                                }

                                if(intresourceNum >0)
                                {
                                    if(!userId.equals(intresourceNum))
                                    {
                                        try{
                                            String sql = " update hrmresource set id="+intresourceNum+" where id="+userId ;
                                            bb.writeLog("sql:"+sql);
                                            rs.execute(sql);
                                        }catch (Exception e){
                                            bb.writeLog("OrganizationSyn-e:"+e);
                                        }

                                        int cusFielddataId = OrganizationSynUtil.getCusFielddataId(intresourceNum+"",1);
                                        if(cusFielddataId>0){
                                            String userUpdateSql2 = " update cus_fielddata set field0=?,field1=?,field2=?,field3=?,field4=?," +
                                                    " field5=?,field6=?,field7=?,field8=?,field9=?,field11=? where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=?";
                                            rs.executeUpdate(userUpdateSql2,new Object[]{field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,field11,intresourceNum});
                                        }else{
                                            String userInsertSql2 = " insert into cus_fielddata(scope,scopeid,id,field0,field1,field2,field3," +
                                                    " field4,field5,field6,field7,field8,field9,field11) values('HrmCustomFieldByInfoType',1,?,?,?,?,?,?,?,?,?,?,?,?)";
                                            rs.executeUpdate(userInsertSql2,new Object[]{intresourceNum,field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,field11});
                                        }
                                    }
                                }

                            }else{
                                count = -10;
                            }
                        } else {


                            long intresourceNum = 0;
                            try{
                                if(!"".equals(empPositionNum) && !"null".equals(empPositionNum) && empPositionNum !=null){
                                    intresourceNum = Long.parseLong(empPositionNum);
                                }else{
                                    intresourceNum = -1;
                                }
                            }catch (Exception e){
                                bb.writeLog("OrganizationSyn-e:"+e);
                                intresourceNum = -2;
                            }

                            if(intresourceNum >0)
                            {
                                rs.executeProc("HrmResourceMaxId_Get", "");
                                rs.next();
                                userId = rs.getInt(1) + "";

                                rs.executeQuery(" select count(1) num from hrmresource where belongto=? ", new Object[]{belongto});
                                rs.next();
                                int num = rs.getInt("num");
                                String loginid = empCode + "czh" + num;

                                String userInsertSql =  " insert into hrmresource(id,loginid,password,lastname,departmentid,subcompanyid1,sex," +
                                        " status,systemlanguage,belongto,accounttype,textfield1,createdate,lastmoddate," +
                                        " created,modified,dsporder,textfield2,workcode,seclevel,messagerurl,resourceimageid) " +
                                        " values("+userId+",'"+loginid+"','"+password+"','"+empName+"','"+deptId+"','"+subcompanyid1+"','"+sex+
                                        "','"+jobState+"',7,'"+belongto+"',1,'"+uuid+"','"+currentDate+"','"+currentDate+"',systimestamp,systimestamp,'"+
                                        dsporder+"','"+textfield2+"','"+empCode+"','"+seclevel+"','"+messagerurl+"','"+resourceimageid+"')";

                                bb.writeLog("userInsertSql:"+userInsertSql);
                                boolean flag = rs.execute(userInsertSql);
                                if(flag)
                                {
                                    count = 2;
                                    try{
                                        String sql = " update hrmresource set id="+intresourceNum+" where id="+userId ;
                                        bb.writeLog("sql:"+sql);
                                        rs.execute(sql);
                                    }catch (Exception e){
                                        bb.writeLog("OrganizationSyn-e:"+e);

                                    }

                                    int cusFielddataId = OrganizationSynUtil.getCusFielddataId(intresourceNum+"",1);
                                    if(cusFielddataId>0){
                                        String userUpdateSql2 = " update cus_fielddata set field0=?,field1=?,field2=?,field3=?,field4=?," +
                                                " field5=?,field6=?,field7=?,field8=?,field9=?,field11=? where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=?";
                                        rs.executeUpdate(userUpdateSql2,new Object[]{field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,field11,intresourceNum});
                                    }else{
                                        String userInsertSql2 = " insert into cus_fielddata(scope,scopeid,id,field0,field1,field2,field3," +
                                                " field4,field5,field6,field7,field8,field9,field11) values('HrmCustomFieldByInfoType',1,?,?,?,?,?,?,?,?,?,?,?,?)";
                                        rs.executeUpdate(userInsertSql2,new Object[]{intresourceNum,field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,field11});
                                    }
                                }else{
                                    count = -11;
                                }
                            }else{
                                count = -100;
                            }
                        }
                    }else{
                        count = -3;
                    }
                }
            }
        }catch (Exception e){

            bb.writeLog("OrganizationSyn-e:"+e);
            count = -2;
        }
        return count;
    }

    /***
     *
     * @param textfield2
     * @return
     */
    public String getSecAccountIdByTextfield2(String textfield2){
        String userId = "";
        if(!"".equals(textfield2) && textfield2 !=null)
        {
            RecordSet rs = new RecordSet();
            rs.executeQuery(" select id from hrmresource where textfield2=? ",new Object[]{textfield2});
            if(rs.next()){
                userId = Util.null2String(rs.getString("id"));
            }
        }
        return userId;
    }

    /****
     *  同步矩阵
     * @param
     */
    public void doMatrixInfo()
    {
        BaseBean bb = new BaseBean();
        try{
            RecordSet rs  = new RecordSet();
            String sql =" select t.ID,l.DEPTHRBP,l.DEPTLEADERS,l.DEPTMP,l.DEPTDIRECTORS,l.COHEAD,k.id as MXRTID,l.id as DATAORDER \n" +
                    " from hrmdepartment t\n" +
                    " inner join hrmdepartmentdefined  l on l.DEPTID = t.id\n" +
                    " left join Matrixtable_2 k on k.id = t.id\n" +
                    " where (t.CANCELED is null or t.CANCELED = 0) " +
                    " ";
            bb.writeLog("sql:"+sql);
            rs.execute(sql);
            Map<String,String> map = null;
            List<Map<String,String>> list = new ArrayList<Map<String,String>>();
            while (rs.next())
            {
                String id = Util.null2String(rs.getString("ID"));
                String depthrbp = Util.null2String(rs.getString("DEPTHRBP"));
                String deptleaders = Util.null2String(rs.getString("DEPTLEADERS"));
                String deptmp = Util.null2String(rs.getString("DEPTMP"));
                String deptdirectors = Util.null2String(rs.getString("DEPTDIRECTORS"));
                String cohead = Util.null2String(rs.getString("COHEAD"));
                String mxrtid = Util.null2String(rs.getString("MXRTID"));
                String dataorder = Util.null2String(rs.getString("DATAORDER"));

                map = new HashMap<String,String>();
                map.put("id",id);
                map.put("depthrbp",depthrbp);
                map.put("deptleaders",deptleaders);
                map.put("deptmp",deptmp);
                map.put("deptdirectors",deptdirectors);
                map.put("cohead",cohead);
                map.put("mxrtid",mxrtid);
                map.put("dataorder",dataorder);
                list.add(map);
            }
            //bb.writeLog("list:"+list.size());
            for(int i=0;i<list.size();i++)
            {
                Map<String,String> datamap = list.get(i);
                String id = Util.null2String(datamap.get("id"));
                String depthrbp = Util.null2String(datamap.get("depthrbp"));
                String deptleaders = Util.null2String(datamap.get("deptleaders"));
                String deptmp = Util.null2String(datamap.get("deptmp"));
                String deptdirectors = Util.null2String(datamap.get("deptdirectors"));
                String cohead = Util.null2String(datamap.get("cohead"));
                String mxrtid = Util.null2String(datamap.get("mxrtid"));
                String dataorder = Util.null2String(datamap.get("dataorder"));

                // bb.writeLog(id+":"+depthrbp+":"+deptleaders+":"+deptdirectors+":"+mxrtid);
                if(!"".equals(mxrtid))
                {
                    //bb.writeLog(id+":"+depthrbp+":"+deptleaders+":"+deptdirectors+":"+mxrtid+":update11");
                    if(!"".equals(id))
                    {
                        sql = " update Matrixtable_2 set DEPTHRBP=?,DEPTLEADERS=?,DEPTMP=?,DEPTDIRECTORS=?,COHEAD=? where id=?";
                        rs.executeUpdate(sql,new Object[]{depthrbp,deptleaders,deptmp,deptdirectors,cohead,id});
                    }
                }else{
                    //bb.writeLog(id+":"+depthrbp+":"+deptleaders+":"+deptdirectors+":"+mxrtid+":insert22");
                    String uuid = UUID.randomUUID().toString();
                    sql = " insert into Matrixtable_2(uuid,dataorder,id,depthrbp,deptleaders,deptmp,deptdirectors,cohead) " +
                            " values(?,?,?,?,?,?,?,?)";
                    rs.executeUpdate(sql,new Object[]{uuid,dataorder,id,depthrbp,deptleaders,deptmp,deptdirectors,cohead});
                }
            }
        }catch (Exception e){
            bb.writeLog("OrganizationSyn-e:"+e);
        }
    }

    /***
     *
     */
    public Map<String,String> setSysActivexCheck(){
        int sucesscount = 0;
        int errorcount = 0;
        Map<String,String> map = new HashMap<String,String>();
        try{
            RecordSet rs  = new RecordSet();
            List<String> list = new ArrayList<String>();
            String sql = " select id from hrmresource where id not in(select userid from Sysactivexcheck)\n" +
                    " and status <4 ";
            rs.execute(sql);
            while (rs.next()){
                String userid = Util.null2String(rs.getString("id"));
                String insql = " insert into Sysactivexcheck(userid,logintype,nocheckplugin)values("+userid+",1,1)";
                list.add(insql);
            }

            if(list.size()>0)
            {
                for(String insql : list)
                {
                    boolean istrue = rs.execute(insql);
                    if(istrue)
                    {
                        sucesscount++;
                    }else{
                        errorcount++;
                    }
                }
            }
        }catch (Exception e){
            new BaseBean().writeLog("OrganizationSyn-e:"+e);
        }

        map.put("sucesscount",sucesscount+"");
        map.put("errorcount",errorcount+"");
        return map;
    }

    /***
     *
     */
    public void setWorkflowUserDefault(){
        try{
            RecordSet rs  = new RecordSet();
            List<String> list = new ArrayList<String>();
            String sql = " select id from hrmresource where id not in( select userid from workflow_RequestUserDefault where unoperatorType <> '1,2' )\n" +
                    " and status =1 ";
            rs.execute(sql);
            while (rs.next()){
                String userid = Util.null2String(rs.getString("id"));
                String insql = " insert into workflow_RequestUserDefault(userid,unoperatorType)values("+userid+",'1,2')";
                list.add(insql);
            }
            if(list.size()>0)
            {
                for(String insql : list)
                {
                    rs.execute(insql);
                }
            }
        }catch (Exception e){
            new BaseBean().writeLog("OrganizationSyn-e:"+e);
        }
    }


    public String getToken()
    {
        OrganizationSynUtil OrganizationSynUtil = new OrganizationSynUtil();
        String appId = "WEAVER";
        String secretKey = "Admin@123" ;
        String accessToken = "" ;
        PropBean pb = new PropBean();
        String orgToken = pb.getPropName("orgToken");
        String url = orgToken+appId+"/"+secretKey;
        Map<String,String> headsMap = new HashMap<String,String>();
        String str = OrganizationSynUtil.sendPost(url,"",headsMap);
        BaseBean bb = new BaseBean();
        bb.writeLog("str:"+str);
        if(!"".equals(str)){
            JSONObject jsonObject = JSONObject.parseObject(str);
            bb.writeLog("jsonObject:"+jsonObject.toJSONString());
            accessToken = Util.null2String(jsonObject.get("accessToken"));
        }
        return accessToken;
    }


    public void updateBelongto(){

        try {
            RecordSet rs = new RecordSet();
            String sql = "update hrmresource set belongto=null where status=1 and belongto = -1";
            rs.executeUpdate(sql);
        }catch (Exception e){
            new BaseBean().writeLog("OrganizationSyn-e:"+e);
        }
    }

    /***
     *
     * @param userids
     */
    public void updateColList(String userids)
    {
        updateColList2dbandtzyd(userids);
        updateColList2ybandwdsq(userids);
        updateColList2yblc(userids);
    }

    /**
     *
     * @param userids
     */
    public void updateColList2dbandtzyd(String userids)
    {
        RecordSet rs = new RecordSet(); //
        RecordSet rs1 = new RecordSet(); //
        BaseBean bb = new BaseBean();

        LinkedHashMap<String,String> indexMap = new LinkedHashMap<String,String>();
        indexMap.put("requestname","0");
        indexMap.put("requestmark","0");
        indexMap.put("creater","0");
        indexMap.put("requestlevel","1");
        indexMap.put("createdate","0");
        indexMap.put("receivedate","1");
        indexMap.put("currentnodeid","0");
        indexMap.put("workflowid","0");
        indexMap.put("unoperators","0");
        indexMap.put("status","1");
        indexMap.put("subwflink","1");

        indexMap.put("requestid","1");

        //String[] dataIndexs = {"requestname","creater","workflowid","requestlevel","createdate","unoperators","receivedate","currentnodeid","requestid"};

        PropBean pb = new PropBean();
        String pageUids = pb.getPropName("PageUidTodo") ;
        bb.writeLog("pageUids:"+pageUids);
        if(!"".equals(pageUids))
        {
            String where  ="";
            if(!"".equals(userids)){
                where = " and id in("+userids+")";
            }

            String pageuids = "";
            String[] pageUidArr = pageUids.split(";");
            for(int n=0;n<pageUidArr.length;n++)
            {
                pageuids += pageuids=="" ?  "'"+pageUidArr[n]+"'" : ",'"+pageUidArr[n]+"'";
            }
            String sql = " select * from hrmresource where id not in (select userid from cloudstore_defcol \n" +
                    " where pageuid in("+pageuids+")) and status = 1 "+where;
            bb.writeLog("sql:"+sql);
            rs.execute(sql);
            while(rs.next())
            {
                String userid = rs.getString("id");
                //bb.writeLog("userid:"+userid);
                String[] pageUidArray = pageUids.split(";");
                for(int n=0;n<pageUidArray.length;n++)
                {
                    String pageUid = pageUidArray[n];

                    int i = 0;
                    for(Map.Entry<String, String> entry : indexMap.entrySet()){
                        String mapkey = entry.getKey();
                        String mapvalue = entry.getValue();

                        String id = "";
                        sql = " select id from cloudstore_defcol where userid=? and pageuid=? and dataIndex=?";
                        //bb.writeLog("sql:"+sql);
                        rs1.executeQuery(sql,new Object[]{userid,pageUid,mapkey});
                        if(rs1.next()){
                            id = Util.null2String(rs1.getString("id"));
                        }
                        //bb.writeLog("id:"+id);
                        if(!"".equals(id))
                        {
                            sql = " update cloudstore_defcol set display=?,orders=? where id=?";
                            //bb.writeLog("sql:"+sql);
                            boolean bool = rs1.executeUpdate(sql,new Object[]{mapvalue,i,id});
                            //bb.writeLog("bool1:"+bool);
                        }else{
                            sql = " insert into cloudstore_defcol(id, dataIndex,sysid, orders, display, pageUid,userid,width) values (cloudstore_defcol_seq.nextval,?,'nullSysId',?,?,?,?,?)";
                            //bb.writeLog("sql:"+sql);
                            boolean bool = rs1.executeUpdate(sql,new Object[]{mapkey,i,mapvalue,pageUid,userid,null});
                            // bb.writeLog("bool2:"+bool);
                        }

                        i++;
                    }
                }
            }
        }
    }


    /**
     *
     * @param userids
     */
    public void updateColList2ybandwdsq(String userids)
    {
        RecordSet rs = new RecordSet(); //
        RecordSet rs1 = new RecordSet(); //
        BaseBean bb = new BaseBean();

        LinkedHashMap<String,String> indexMap = new LinkedHashMap<String,String>();

        indexMap.put("requestname","0");
        indexMap.put("requestmark","0");
        indexMap.put("creater","0");
        indexMap.put("requestlevel","1");
        indexMap.put("createdate","0");
        indexMap.put("operatedateNew","1");
        indexMap.put("currentnodeid","0");
        indexMap.put("workflowid","0");
        indexMap.put("unoperators","0");
        indexMap.put("status","1");
        indexMap.put("subwflink","1");

        indexMap.put("requestid","0");


        //String[] dataIndexs = {"requestname","creater","workflowid","requestlevel","createdate","unoperators","receivedate","currentnodeid","requestid"};

        PropBean pb = new PropBean();
        String pageUids = pb.getPropName("PageUidDone") ;
        bb.writeLog("pageUids:"+pageUids);
        if(!"".equals(pageUids))
        {
            String where  ="";
            if(!"".equals(userids)){
                where = " and id in("+userids+")";
            }
            String pageuids = "";
            String[] pageUidArr = pageUids.split(";");
            for(int n=0;n<pageUidArr.length;n++)
            {
                pageuids += pageuids=="" ?  "'"+pageUidArr[n]+"'" : ",'"+pageUidArr[n]+"'";
            }
            String sql = " select * from hrmresource where id not in (select userid from cloudstore_defcol \n" +
                    " where pageuid in("+pageuids+")) and status = 1 "+where;
            bb.writeLog("sql:"+sql);
            rs.execute(sql);
            while(rs.next())
            {
                String userid = rs.getString("id");
                bb.writeLog("userid:"+userid);
                String[] pageUidArray = pageUids.split(";");
                for(int n=0;n<pageUidArray.length;n++)
                {
                    String pageUid = pageUidArray[n];

                    int i = 0;
                    for(Map.Entry<String, String> entry : indexMap.entrySet()){
                        String mapkey = entry.getKey();
                        String mapvalue = entry.getValue();

                        String id = "";
                        sql = " select id from cloudstore_defcol where userid=? and pageuid=? and dataIndex=?";
                        //bb.writeLog("sql:"+sql);
                        rs1.executeQuery(sql,new Object[]{userid,pageUid,mapkey});
                        if(rs1.next()){
                            id = Util.null2String(rs1.getString("id"));
                        }
                        //bb.writeLog("id:"+id);
                        if(!"".equals(id))
                        {
                            sql = " update cloudstore_defcol set display=?,orders=? where id=?";
                            //bb.writeLog("sql:"+sql);
                            boolean bool = rs1.executeUpdate(sql,new Object[]{mapvalue,i,id});
                            //bb.writeLog("bool1:"+bool);
                        }else{
                            sql = " insert into cloudstore_defcol(id, dataIndex,sysid, orders, display, pageUid,userid,width) values (cloudstore_defcol_seq.nextval,?,'nullSysId',?,?,?,?,?)";
                            //bb.writeLog("sql:"+sql);
                            boolean bool = rs1.executeUpdate(sql,new Object[]{mapkey,i,mapvalue,pageUid,userid,null});
                            //bb.writeLog("bool2:"+bool);
                        }

                        i++;
                    }
                }
            }
        }
    }


    public void updateColList2yblc(String userids)
    {
        RecordSet rs = new RecordSet(); //
        RecordSet rs1 = new RecordSet(); //
        BaseBean bb = new BaseBean();

        LinkedHashMap<String,String> indexMap = new LinkedHashMap<String,String>();

        indexMap.put("requestname","0");
        indexMap.put("requestmark","0");
        indexMap.put("creater","0");
        indexMap.put("createdate","0");
        indexMap.put("workflowid","0");
        indexMap.put("currentnodeid","0");

        indexMap.put("requestlevel","1");
        indexMap.put("receivedate","1");
        indexMap.put("operatedateNew","1");
        indexMap.put("status","1");

        indexMap.put("unoperators","1");
        indexMap.put("sysname","1");
        indexMap.put("subwflink","1");


        //String[] dataIndexs = {"requestname","creater","workflowid","requestlevel","createdate","unoperators","receivedate","currentnodeid","requestid"};

        PropBean pb = new PropBean();
        String pageUids = pb.getPropName("PageUidYblc") ;
        bb.writeLog("pageUids:"+pageUids);
        if(!"".equals(pageUids))
        {
            String where  ="";
            if(!"".equals(userids)){
                where = " and id in("+userids+")";
            }
            String pageuids = "";
            String[] pageUidArr = pageUids.split(";");
            for(int n=0;n<pageUidArr.length;n++)
            {
                pageuids += pageuids=="" ?  "'"+pageUidArr[n]+"'" : ",'"+pageUidArr[n]+"'";
            }
            String sql = " select * from hrmresource where id not in (select userid from cloudstore_defcol \n" +
                    " where pageuid in("+pageuids+")) and status = 1 "+where;
            bb.writeLog("sql:"+sql);
            rs.execute(sql);
            while(rs.next())
            {
                String userid = rs.getString("id");
                bb.writeLog("userid:"+userid);
                String[] pageUidArray = pageUids.split(";");
                for(int n=0;n<pageUidArray.length;n++)
                {
                    String pageUid = pageUidArray[n];

                    int i = 0;
                    for(Map.Entry<String, String> entry : indexMap.entrySet()){
                        String mapkey = entry.getKey();
                        String mapvalue = entry.getValue();

                        String id = "";
                        sql = " select id from cloudstore_defcol where userid=? and pageuid=? and dataIndex=?";
                        bb.writeLog("sql:"+sql);
                        rs1.executeQuery(sql,new Object[]{userid,pageUid,mapkey});
                        if(rs1.next()){
                            id = Util.null2String(rs1.getString("id"));
                        }
                        //bb.writeLog("id:"+id);
                        if(!"".equals(id))
                        {
                            sql = " update cloudstore_defcol set display=?,orders=? where id=?";
                            //bb.writeLog("sql:"+sql);
                            boolean bool = rs1.executeUpdate(sql,new Object[]{mapvalue,i,id});
                            //bb.writeLog("bool1:"+bool);
                        }else{
                            sql = " insert into cloudstore_defcol(id, dataIndex,sysid, orders, display, pageUid,userid,width) values (cloudstore_defcol_seq.nextval,?,'nullSysId',?,?,?,?,?)";
                            //bb.writeLog("sql:"+sql);
                            boolean bool = rs1.executeUpdate(sql,new Object[]{mapkey,i,mapvalue,pageUid,userid,null});
                            //bb.writeLog("bool2:"+bool);
                        }

                        i++;
                    }
                }
            }
        }
    }

    /**
     * 清除缓存
     */
    public void removeCache(){
        ResourceComInfo resComInfo;
        DepartmentComInfo deptComInfo;
        JobTitlesComInfo jobTitlesComInfo;
        try {
            resComInfo = new ResourceComInfo();

            resComInfo.removeResourceCache();
            deptComInfo = new DepartmentComInfo();
            deptComInfo.removeCompanyCache();
            jobTitlesComInfo = new JobTitlesComInfo();
            jobTitlesComInfo.removeCache();
        } catch (Exception e) {
            new BaseBean().writeLog("OrganizationSyn-e:"+e);
        }
    }


}
